/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.ruby_string.delayed;

import moved.org.objectweb.asm.Attribute;
import moved.org.objectweb.asm.MethodVisitor;
import picounit.util.Equal;

public class AttributeInstruction extends AbstractMethodInstruction implements Equal<AttributeInstruction> {
	private final Attribute attribute;

	public AttributeInstruction(Attribute attribute) {
		this.attribute = attribute;
	}
	
	public boolean hasAttribute(Attribute attribute) {
		return this.attribute.equals(attribute);
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Equal methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public boolean equalTo(AttributeInstruction other) {
		return other.hasAttribute(attribute);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// MethodInstruction Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public void accept(MethodVisitor methodVisitor) {
		methodVisitor.visitAttribute(attribute);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public boolean equals(Object object) {
		if (object == null || !(object.getClass().equals(getClass()))) {
			return false;
		}

		AttributeInstruction other = (AttributeInstruction) object;

		return attribute.equals(other.attribute);
	}
}
